<?php

namespace Admin\Controller;

use Admin\Builder\AdminListBuilder;
use Admin\Builder\AdminConfigBuilder;

class ApiController extends AdminController
{
    public function index()
    {
        $this->redirect('config');
    }

    public function config()
    {
        $builder = new AdminConfigBuilder();
        $data = $builder->handleConfig();
        $data['accesstoken'] = md5(base64_encode($data['ACCESS_TOKEN']));
        $builder->title('基本设置')
            ->data($data)
            ->keyText('ACCESS_TOKEN', 'access_token', '应用的access_token，输入一个字符串，系统将进行加密。')
            ->keyDefault('ACCESS_TOKEN','xxxxxxx')
            ->keyLabel('accesstoken', '以下部分为access_token', '加密后的token，应用最终使用的access_token')
            ->buttonSubmit('', '保存');
        $builder->display();
    }

    public function sort()
    {
            $builder = new AdminConfigBuilder();
            $data = $builder->handleConfig();
            $builder->title('APP相关');
            $builder->keyKanban('SHOW_MOD_TAB', '开启客户端模块列表');
            $builder->keyBool('IS_NEED_ADMIN', '是否允许客户端用户自行配置', '默认为否');
            $mod_list = D('module')->where(array('is_setup' => 1))->select();
            foreach ($mod_list as $k => &$val) {
                $val = array('data-id' => $val['name'], 'title' => $val['alias']);
            }
            unset($val);
            $default = array(array('data-id' => 'disable', 'title' => '禁用', 'items' => $mod_list), array('data-id' => 'enable', 'title' => '开启', 'items' => array()));
            $data['SHOW_MOD_TAB'] = $builder->parseKanbanArray($data['SHOW_MOD_TAB'], $mod_list, $default);
            $builder->keyText('APP_MOD_URL', 'APP下载链接')->keyText('APP_VERSIONS', 'APP版本号')->keySingleFile('APP_MOD_FILE', '最新文件包', '存放最新文件包');
            $builder->data($data);
            $builder->keyDefault('IS_NEED_ADMIN',0);
            $builder->buttonSubmit();
            $builder->display();
    }



}
